package com.my.aslife.controller;


import com.my.aslife.module.common.Constant;
import com.my.aslife.module.common.ErrorCode;
import com.my.aslife.module.common.PageRequestVo;
import com.my.aslife.module.common.ResponseResult;
import com.my.aslife.module.entity.Sensitive;
import com.my.aslife.service.SensitiveService;
import com.my.aslife.utils.CheckSensitiveUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * @author mayuan
 * @description TODO
 */
@RestController
@Slf4j
@RequestMapping("/api/my/sensitive")
public class SensitiveController {

    @Autowired
    private SensitiveService sensitiveService;

    @GetMapping("/list")
    public ResponseResult getSensitiveListInfo(@RequestParam Integer current, @RequestParam Integer pageSize) {
        PageRequestVo pageRequestVo = new PageRequestVo(current, pageSize);
        return sensitiveService.getSensitiveListInfo(pageRequestVo);
    }

    @PostMapping("/info/{id}")
    public ResponseResult querySensitiveNameById(@PathVariable Integer id){
        return sensitiveService.querySensitiveNameById(id);
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteSensitiveById(@PathVariable Integer id){
        return sensitiveService.deleteSensitiveById(id);
    }

    @PostMapping("/insert")
    public ResponseResult insertSensitive(@RequestBody Sensitive sensitive){
        if (sensitive.getSensitive() == null || sensitive.getSensitive().trim().length() == 0) {
            return ResponseResult.failed(ErrorCode.PARAMS_NOT_NULL);
        }
        return sensitiveService.insertSensitive(sensitive);
    }

    @PostMapping("/update")
    public ResponseResult updateSensitive(@RequestBody Sensitive sensitive){
        if (sensitive.getSensitive() == null || sensitive.getSensitive().trim().length() == 0) {
            return ResponseResult.failed(ErrorCode.PARAMS_NOT_NULL);
        }
        return sensitiveService.updateSensitive(sensitive);
    }
}
